const { terser } = require("rollup-plugin-terser");
const resolve = require("@rollup/plugin-node-resolve");
const commonjs = require("@rollup/plugin-commonjs");
const typescript = require("rollup-plugin-typescript2");
const { dts } = require("rollup-plugin-dts");
const cleaner = require("rollup-plugin-cleaner");
const path = require("path");
const copy = require("rollup-plugin-copy");
const json = require("@rollup/plugin-json");
module.exports = [
  {
    input: "src/index.ts", // 入口文件
    // external: ["/node_modules/", "test", "workspace", "dist"],
    // output: {
    //   dir: "./dist/index.js",
    // },
    output: [
      {
        dir: "./dist",
        format: "cjs",
        name: "i18nTools",
      },
    ],
    external: [
      "fs",
      "path",
      "chalk",
      "@babel/core",
      // "@babel/traverse",
      // "@babel/generator",
      // "@babel/template",
      "lodash",
      "lodash/isEmpty",
      "@vue/compiler-sfc",
      "htmlparser2",
      "prettier",
      "ejs",
      "axios",
      "crc/crc32",
      "crypto",
    ],
    plugins: [
      cleaner({
        targets: ["./dist"], // 要清理的目录
      }),
      typescript({
        useTsconfigDeclarationDir: true,
      }),
      resolve(), // 解析 node_modules 中的模块
      commonjs(), // 将 CommonJS 转换为 ES 模块
      json(),
      // terser(), // 压缩输出的代码
    ],
  },
  {
    input: "src/index.ts", // 入口文件
    output: [
      {
        file: path.resolve("./dist/index.d.ts"),
        format: "es",
      },
    ],
    plugins: [
      dts(),
      copy({
        targets: [
          // 目标对象数组
          { src: "./src/types", dest: "./dist" },
        ],
      }),
    ],
  },
];
